//package com.util.ossutil;
//
//import com.aliyun.oss.OSS;
//import com.aliyun.oss.model.GetObjectRequest;
//import com.aliyun.oss.model.ObjectMetadata;
//import com.aliyun.oss.model.PutObjectRequest;
//import com.aliyuncs.DefaultAcsClient;
//import com.aliyuncs.IAcsClient;
//import com.aliyuncs.auth.sts.AssumeRoleRequest;
//import com.aliyuncs.auth.sts.AssumeRoleResponse;
//import com.aliyuncs.exceptions.ClientException;
//import com.aliyuncs.profile.DefaultProfile;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//
//import java.io.ByteArrayInputStream;
//import java.io.File;
//import java.io.IOException;
//import java.io.InputStream;
//import java.net.URL;
//import java.net.URLConnection;
//import java.util.ArrayList;
//import java.util.List;
///**
// * STS临时凭证上传
// */
//@Component
//public class OSSUtil {
//    private static final Logger LOGGER = LoggerFactory.getLogger(OSSUtil.class);
//    private static final String APP_ADAPTER_FILEPATH = "/home/work/wechat/";
//
//    public AssumeRoleResponse getSTSCredential() {
//        IAcsClient stsClient = null;
//        AssumeRoleResponse acsResponse = null;
//        try {
//            DefaultProfile.addEndpoint("", "Sts", STS_ENDPOINT_EVV);
//            stsClient = new DefaultAcsClient(DefaultProfile.getProfile("", ACCESS_KEY_ID_ENV, ACCESS_KEY_SECRET_ENV));
//            AssumeRoleRequest request = new AssumeRoleRequest();
//            request.setRoleArn(ROLE_ARN_ENV);
//            request.setRoleSessionName(ROLE_SESSION_NAME_ENV);
//            acsResponse = stsClient.getAcsResponse(request);
//        }catch (ClientException e){
//            LOGGER.error("getSTSCredential error:{}==errorCode:{}", e.getErrMsg(), e.getErrCode());
//        }finally {
//            if (stsClient != null) {
//                stsClient.shutdown();
//            }
//        }
//        return acsResponse;
//    }
//
//    /**
//     * img图片上传
//     */
//    public void uploadFileToOSS(OSS ossClient, String fileUrl, String objectName) {
//        try {
//            URL url = new URL(fileUrl);
//            URLConnection connection = url.openConnection();
//            try(InputStream inputStream = connection.getInputStream()) {
//                ossClient.putObject(new PutObjectRequest(OSS_BUCKET, objectName, inputStream));
//            }
//        }catch (IOException e){
//            LOGGER.error("getSTSCredential error", e);
//        }
//    }
//
//    public void uploadInputStreamToOSS(OSS ossClient, ByteArrayInputStream byteArrayInputStream, ObjectMetadata metadata, String objectName) {
//        try {
//            ossClient.putObject(OSS_BUCKET, objectName, byteArrayInputStream, metadata);
//        }catch (Exception e){
//            LOGGER.error("getSTSCredential error", e);
//        }
//    }
//
//    public String downOssFileToFds(OSS ossClient, String objectNameStr) {
//        List<String> fdsList = new ArrayList<>();
//        String[] objectNameList = objectNameStr.split(",");
//        for (String objectName : objectNameList) {
//            String fileName = objectName.substring(objectName.lastIndexOf("/") + 1);
//            String tempFile = APP_ADAPTER_FILEPATH + fileName;
//            File file = new File(tempFile);
//            ossClient.getObject(new GetObjectRequest(OSS_BUCKET, objectName), file);
//            //上传fds
//            try {
////                String fdsUrl = FileStorageUtils.upload(tempFile, AppConstants.channel);
////                fdsList.add(fdsUrl);
//            } catch (Exception e) {
//                LOGGER.error("fds upload failed error:{}==tempFile=={}", e, tempFile);
//            }
//
//            if(file.delete()){
//                LOGGER.info("oss file deleted successfully:{}", tempFile);
//            }else {
//                LOGGER.error("oss file deleted failed:{}", tempFile);
//            }
//
//        }
//        return String.join(",", fdsList);
//    }
//}
